home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 13 - 1997 (partial) / 13.02 Feb 97 / Challenge, Router Rules / BitGrpMapper.h < prev    next >
Encoding:
Text File  |  1997-01-03  |  1.3 KB  |  65 lines  |  [TEXT/R*ch]

  1. // ---------------------------------------------------------
  2. // class BitGrpMapper 
  3. // ---------------------------------------------------------
  4.  
  5.  
  6. #ifndef NULL
  7. const void * const NULL = 0;
  8. #endif
  9.  
  10. typedef unsigned long ulng;
  11.  
  12. struct IndexEntry {
  13.     long    index[4];
  14. };
  15.  
  16.  
  17. class BitGrpMapper {
  18.     
  19. public:
  20.     static long      ubTable[33];
  21.     static long      lbTable[33];
  22.  
  23.     long        chunkSize;        // 1, 2, 4 or 8 bits per chunk
  24.     long        chunkCount;        // # of chunks/digits in group index
  25.     ulng        firstMask;    // used to reset curMask
  26.     ulng        firstMatchBit;
  27.     long        numGrpLists;
  28.  
  29.     void         Init( long    chunkSize,
  30.                                 long    numBits );
  31.                                                             
  32.     inline long        LookUp( ulng        value );            
  33.  
  34. private:
  35.     static IndexEntry lookupTable2[];
  36.     static IndexEntry lookupTable4[];
  37.     static IndexEntry lookupTable8[];
  38.     
  39.         
  40.     IndexEntry        *lookupTable;    // lookup group index
  41.     
  42.  
  43. #if WRITE_LOOKUP_TABLES == 1
  44.     void        CalcLookupTable(     IndexEntry    lookupTbl[],
  45.                                                         long                chunkSz );
  46.  
  47.     void    WriteLookupTable( ofstream        &file,
  48.                                                     IndexEntry    table[],
  49.                                                     char*                tableName );
  50. #endif    
  51. };
  52.  
  53.  
  54. inline long BitGrpMapper::LookUp( ulng    value )            
  55. {
  56.     long    index = lookupTable[value >> 24].index[0];
  57.     
  58.     index += lookupTable[(value >> 16) & 0xff].index[1];
  59.     index += lookupTable[(value >> 8) & 0xff].index[2];
  60.     index += lookupTable[value & 0xff].index[3];
  61.     
  62.     return index;
  63. }
  64.  
  65.